package pri.zxx.webdemo.entity.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;


/**
 * @author Twilight
 * @desc
 * @createTime 2020-05-23-21:19
 */
@Tag(name = "分页对象")
public class PageDto {
	@Schema(name = "当前页")
	public Integer pageIndex;
	@Schema(name = "每页数量")
	public Integer size;
	@Schema(name = "总数量")
	private Integer totalNum;
	@Schema(name = "总页数")
	private Integer totalPage;
	@Schema(name = "偏移量")
	private Integer offset;

	public PageDto() {
	}

	public PageDto(Integer pageIndex, Integer size) {
		if (pageIndex == null || pageIndex < 0) {
			pageIndex = 1;
		}
		if (size == null || size < 0) {
			size = 10;
		}
		this.pageIndex = pageIndex;
		this.size = size;
		this.offset = (pageIndex - 1) * size;
	}

	public PageDto(Integer pageIndex, Integer size, Integer totalNum) {
		if (pageIndex == null || pageIndex < 0) {
			pageIndex = 1;
		}
		if (size == null || size < 0) {
			size = 10;
		}
		this.pageIndex = pageIndex;
		this.size = size;
		this.totalNum = totalNum;
		this.offset = (pageIndex - 1) * size;
		this.totalPage = (totalNum / size) + 1;
	}

	public static PageDto get(Integer page, Integer size) {
		return new PageDto(page, size);
	}

	@Override
	public String toString() {
		return "Page{" +
				"pageIndex=" + pageIndex +
				", size=" + size +
				", totalNum=" + totalNum +
				", totalPage=" + totalPage +
				'}';
	}

	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

	public Integer getTotalNum() {
		return totalNum;
	}

	public void setTotalNum(Integer totalNum) {
		if (totalNum == null || totalNum < 0) {
			totalNum = 0;
		}
		this.totalNum = totalNum;
		this.totalPage = (totalNum / size) + 1;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getOffset() {
		return offset;
	}

	public void setOffset(Integer offset) {
		this.offset = offset;
	}
}
